package com.hh.servlet.schedule;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.hh.dao.NurseDAO;
import com.hh.dao.ScheduleDAO;

/**
 * Servlet implementation class NurseList
 */
@WebServlet("/NurseList")
public class NurseList extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public NurseList() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setHeader("content-type", "text/html;charset=UTF-8");
		String rylx = request.getParameter("rylx");
		String rybm = request.getParameter("rybm");
		String ksdm = request.getParameter("ksdm");
		NurseDAO ndao = new NurseDAO();
//		JSONArray depts = ndao.getDepts(rybm);
//		for(int k=0;k<depts.size();k++){
//			JSONObject dept = depts.getJSONObject(k);
			JSONArray nurses = ndao.getNurses(rylx,ksdm);
			ScheduleDAO dao = new ScheduleDAO();
			for(int i=0;i<nurses.size();i++){
				JSONObject nurse = nurses.getJSONObject(i);
				JSONArray schedules = dao.getSchedulesByNurseAllWeek(nurse.getString("ygdm"));
				for(int j=0;j<schedules.size();j++){
					JSONObject schedule = schedules.getJSONObject(j);
					nurse.put(schedule.getString("pbrq").substring(0,10), schedule.getString("ksrq")+"-"+schedule.getString("jsrq"));
				}
			}
//			dept.put("nurses", nurses);
//		}
		request.setAttribute("nurses", nurses);
//		request.setAttribute("depts", depts);
		request.getRequestDispatcher("schedule_nurse.jsp").forward(request,response); 
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
